package com.example.mrv.hrd;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MenuActivity extends AppCompatActivity {
    private final static int REQUESTCODE = 1;
    public static String isContinue = "isContinue";
    private AlertDialog showLevelBox;
    private int chooseLevel;
    private Intent menuMusicIntent;

    public MenuActivity() {
        chooseLevel = basicGame.level;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        menuMusicIntent = new Intent(MenuActivity.this,menuMusic.class);
        startService(menuMusicIntent);
    }
    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        stopService(menuMusicIntent);
        super.onStop();
    }
    public void LaunchGameActivity(View view) {
        Intent intent = new Intent(this, GameActivity.class);
        String message = "false";
        intent.putExtra(isContinue, message);
        basicGame.isContinue = true;
        startActivityForResult(intent,REQUESTCODE);
    }

    public void continueGameActivity(View view) {
//        Log.d("continueGame","run");
        Intent intent = new Intent(this, GameActivity.class);
        String message;
        if( basicGame.isContinue) {
            message = "true";
        }
        else {
            message = "false";
        }
        intent.putExtra(isContinue, message);
        startActivity(intent);
    }

    public void showLevel(View view) {
        final String[] items = {"横刀立马", "阿谀逢迎", "百步穿杨", "冰心玉壶","兵不厌诈", "测试"};
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this, R.style.showLevel);
        alertBuilder.setTitle("选择关卡");

        alertBuilder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
//                Toast.makeText(MenuActivity.this, items[i], Toast.LENGTH_SHORT).show();
                chooseLevel = i;
            }
        });
        alertBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                showLevelBox.dismiss();
//                Toast.makeText(MenuActivity.this, ":" + i, Toast.LENGTH_SHORT).show();
                basicGame.level  = chooseLevel;
            }
        });

        alertBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                showLevelBox.dismiss();
            }
        });

        showLevelBox = alertBuilder.create();
        showLevelBox.show();
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        startService(menuMusicIntent);
    }
}
